package org.grow.leavejpa.controller;

import org.grow.leavejpa.entity.enums.ApplyState;
import org.grow.leavejpa.entity.enums.AuditState;
import org.grow.leavejpa.entity.enums.LeaveType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: xwg
 * @CreateDate: 21-6-9
 */
@RestController
@RequestMapping("/basic")
public class CommonController {

    @GetMapping("/LeaveTypes")
    public List<Map<String, Object>> leaveTypes() {
        return Arrays.stream(LeaveType.values())
                .map(x -> {
                    Map<String, Object> map = new TreeMap<>();
                    map.put("index", x.ordinal());
                    map.put("value", x.name());
                    map.put("text", x.getText());
//                    x.getText();
//                    x.name();
//                    x.ordinal();
                    return map;
                }).collect(Collectors.toList());
    }

    @GetMapping("/ApplyStates")
    public List<Map<String, Object>> applyStates() {
        return Arrays.stream(ApplyState.values())
                .map(x -> {
                    Map<String, Object> map = new TreeMap<>();
                    map.put("index", x.ordinal());
                    map.put("value", x.name());
                    map.put("text", x.getText());
                    return map;
                }).collect(Collectors.toList());

    }

    @GetMapping("/AuditStates")
    public List<Map<String, Object>> auditStates() {

        return Arrays.stream(AuditState.values())
                .map(x -> {
                    TreeMap<String, Object> obj = new TreeMap<>();
                    obj.put("text", x.getText());
                    obj.put("value", x.name());
                    obj.put("index", x.ordinal());
                    return obj;
                }).collect(Collectors.toList());

    }


}
